package com.dup.algms;

import com.dup.factory.MatchAlgmsFactory;
import com.dup.interfaces.MatchEx;

public class StdPerfectMatchEx implements MatchEx {

	public String old_str, new_str, old_str_up, new_str_up;

	@Override
	public boolean machWithWord(String oldStr, String newStr) {
		old_str = oldStr;
		new_str = newStr;
		old_str_up = oldStr.toUpperCase();
		new_str_up = newStr.toUpperCase();
		if (!MatchAlgmsFactory.getMatchInstance("perfect").machWithWord(oldStr,
				newStr)) {
			if (matchWithIgnoreCase()) {
				return true;
			}
			return false;
		} else
			return true;
	}

	private boolean matchWithIgnoreCase() {
		if (new_str_up.equals(old_str_up)) {
			MatchAlgmsFactory.setMsg("Content Match - Ignore case");
		} else {
			String old_str_nospace = old_str.replaceAll("\\s+", "");
			String new_str_nospace = new_str.replaceAll("\\s+", "");

			if (new_str_nospace.equals(old_str_nospace)) {
				MatchAlgmsFactory.setMsg("Content Match - Ignore Space");
			} else if (new_str_nospace.toUpperCase().equals(
					old_str_nospace.toUpperCase())) {
				MatchAlgmsFactory.setMsg("Content Match - Ignore Space & case");
			}
		}
		return true;
	}

}
